package com.zdkj.subway.support.controller;

import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.support.dto.in.SwStLogSetDTO;
import com.zdkj.subway.support.entity.SwStLogSet;
import com.zdkj.subway.support.service.SwStLogSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 票务日志设置表
 *
 * @author cui_com
 * @date 2020-01-08 17:21:50
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swstlogset")
@Api(value = "swstlogset", tags = "票务日志设置表管理")
public class SwStLogSetController {

    private final SwStLogSetService swStLogSetService;


    /**
     * @return R
     */
    @ApiOperation(value = "查找日志设置", notes = "查找日志设置")
    @GetMapping
    public R getLogSet() {
        List<SwStLogSet> list = swStLogSetService.list();
        return R.ok(list.isEmpty() ? new SwStLogSet() : list.get(0));
    }

    /**
     * 修改票务日志设置表
     *
     * @param swStLogSet 票务日志设置表
     * @return R
     */
    @ApiOperation(value = "修改票务日志设置表", notes = "修改票务日志设置表")
    @SysLog("修改票务日志设置表")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('support_sw_st_log_set_edit')")
    public R updateOrSave(@RequestBody SwStLogSetDTO swStLogSet) {
        SwStLogSet obj = ObjectUtils.getDefaultObj(SwStLogSet.class);
        BeanUtils.copyProperties(swStLogSet, obj);
        return R.ok(swStLogSetService.saveOrUpdate(obj));
    }

}
